package com.cction.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.cction.R
import com.cction.comm.GridDividerItemDecoration
import com.cction.entry.ItemBean
import com.zhy.adapter.recyclerview.CommonAdapter
import com.zhy.adapter.recyclerview.base.ViewHolder
import kotlinx.android.synthetic.main.simulation_main.*
import kotlinx.android.synthetic.main.title_bar.*


/**
 * 模拟页面
 */
class SimulationFragment : Fragment() {
    private val arrayList = ArrayList<ItemBean>()
    private lateinit var adapter: CommonAdapter<ItemBean>

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.simulation_main, container, false)
    }


    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        initView()
    }


    private fun initView() {
        title_bar_back.visibility = View.GONE
        title_bar_other.visibility = View.GONE
        title_bar_title.text = "模拟场景"
        arrayList.clear()
        arrayList.add(ItemBean(R.mipmap.ssq, "双色球"))
        arrayList.add(ItemBean(R.mipmap.dlt, "大乐透"))
        arrayList.add(ItemBean(R.mipmap.kp3, "快3"))
        arrayList.add(ItemBean(R.drawable.svg_stock, "股票"))
        arrayList.add(ItemBean(R.drawable.svg_fund, "基金"))
        arrayList.add(ItemBean(R.drawable.svg_dream, "梦想"))

        simulation_recycler.layoutManager = GridLayoutManager(context, 3)
        simulation_recycler.addItemDecoration(GridDividerItemDecoration(context))

        adapter = object : CommonAdapter<ItemBean>(context, R.layout.item_main, arrayList) {
            override fun convert(holder: ViewHolder, t: ItemBean, position: Int) {
                holder.setImageResource(R.id.item_image, t.icon)
                holder.setText(R.id.item_name, t.name)
            }
        }
        simulation_recycler.adapter = adapter
    }
}

